package com.example.demo.model.entity.GisEntity;

import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.annotation.TableField;
import com.example.demo.model.DTO.GIsModel;
import com.example.demo.model.DTO.Location;
import lombok.Data;

import java.lang.reflect.Field;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.Map;

@Data
@TableName("hy_parking")
public class Parking {
    @TableField("id")
    private String id;

    @TableField("parent_tenant_id")
    private Integer parentTenantId;

    @TableField("tenant_id")
    private Integer tenantId;

    @TableField("parking_lot_number")
    private String parkingLotNumber;

    @TableField("parking_lot_name")
    private String parkingLotName;

    @TableField("parking_lot_type")
    private String parkingLotType;

    @TableField("district")
    private String district;

    @TableField("street")
    private String street;

    @TableField("total_spots")
    private Integer totalSpots;

    @TableField("available_spots")
    private Integer availableSpots;

    @TableField("parking_lot_form")
    private String parkingLotForm;

    @TableField("hourly_rate")
    private Double hourlyRate;

    @TableField("charging_standard")
    private String chargingStandard;

    @TableField("price_level")
    private Integer priceLevel;

    @TableField("longitude")
    private Double longitude;

    @TableField("latitude")
    private Double latitude;

    @TableField("address")
    private String address;

    @TableField("main_image")
    private String mainImage;

    @TableField("creator_user")
    private String creatorUser;

    @TableField("creation_time")
    private LocalDateTime creationTime;

    @TableField("modifier_user")
    private String modifierUser;

    @TableField("modification_time")
    private LocalDateTime modificationTime;

    @TableField("remark")
    private String remark;

    @TableField("is_deleted")
    private String isDeleted;

    @TableField("is_public")
    private String isPublic;

    @TableField("business_hours")
    private String businessHours;

    @TableField("property_company")
    private String propertyCompany;

    @TableField("phone")
    private String phone;

    @TableField("tags")
    private String tags;

    @TableField("merchant_number")
    private String merchantNumber;

    @TableField("huize_parking_lot_number")
    private String huizeParkingLotNumber;

    @TableField("discount_rule")
    private String discountRule;

    @TableField("discount_details")
    private String discountDetails;

    // 注意：对于 location 字段，你可能需要使用特定的类型来处理地理位置数据，
    // 这取决于你如何在 Java 中处理这类数据。
    @TableField("location")
    private String  location;

    public Location getLocation() {
        System.out.println(this.location);
        String wkbData =this.location;
        if (this.location != null) {
            Location location = new Location(wkbData);
            return location;
        }

        return null;
    }

    public GIsModel toGIsModel(String type, String name) {
        GIsModel gIsModel = new GIsModel();
        gIsModel.setId(this.id);
        gIsModel.setType(type);
        Location location=new Location(this.location);
        gIsModel.setLocation(location);
        gIsModel.setName(name);

        Map<String, Object> specialAttributes = new HashMap<>();
        Field[] fields = this.getClass().getDeclaredFields();

        for (Field field : fields) {
            field.setAccessible(true);
            try {
                specialAttributes.put(field.getName(), field.get(this));
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }
        }
        gIsModel.setSpecial_attributes(specialAttributes);

        return gIsModel;
    }
}
